<?php

declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace Plugin\Attractions\Commerce\Service\Commerce_merchant;

use Plugin\Attractions\Commerce\Repository\Commerce_merchant\CommerceMerchantRepository;
use App\Service\IService;

/**
 * 商户信息服务类
 */
final class CommerceMerchantService extends IService
{
    public function __construct(
        protected readonly CommerceMerchantRepository $repository
    ) {}

    public function merchantPage(array $params, int $page = 1, int $pageSize = 10): array
    {
        $result = $this->repository->perQuery(
            $this->repository->getQuery()->select('id', 'spot_id', 'merchant_name', 'merchant_type', 'contact_person', 'contact_phone', 'contact_email', 'address', 'open_time', 'close_time', 'status'),
            $params
        )->paginate(
            perPage: $pageSize,
            pageName: $this->repository::PER_PAGE_PARAM_NAME,
            page: $page,
        );
        return $this->repository->handlePage($result);
    }
}
